package com.tengju.bff.interfaces.covercharge.service.bestsign.convert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.tengju.bff.interfaces.covercharge.constant.ContractUserTypeEnum;
import com.tengju.bff.interfaces.covercharge.entity.vo.contract.ApplyCertificateResVo;
import com.tengju.bff.interfaces.covercharge.entity.vo.contract.ApplyCertificateStatusResVo;
import com.tengju.bff.interfaces.covercharge.entity.vo.contract.CompanyCertApplyVo;
import com.tengju.bff.interfaces.covercharge.entity.vo.contract.PersonCertApplyVo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liang_shi
 * @date 2020/7/13 15:27
 * @description 证书申请
 */
public class BestSignApplyCertConverter {

    /**
     * 注册个人用户并申请证书
     *
     * @param account   个人注册账户
     * @param applyCert 是否申请证书 1 是 0 否
     * @param person    个人信息
     * @return 业务报文
     */
    public static Map<String, Object> packagePersonApplyCertReq(String account, String applyCert, PersonCertApplyVo person) {
        //1.业务报文
        Map<String, Object> bizMap = Maps.newHashMap();
        bizMap.put("account", account);
        bizMap.put("name", person.getName());
        bizMap.put("userType", String.valueOf(ContractUserTypeEnum.SINGLE.getType()));
        bizMap.put("mail", person.getMail());
        bizMap.put("mobile", person.getMobile());
        //2.用户证件信息对象
        JSONObject credential = new JSONObject();
        credential.put("identity", person.getIdentity());
        credential.put("identityType", person.getIdentityType().getType());
        credential.put("contactMobile", person.getContactMobile());
        credential.put("contactMail", person.getContactMail());
        credential.put("province", person.getProvince());
        credential.put("city", person.getCity());
        credential.put("address", person.getAddress());
        bizMap.put("credential", credential);
        bizMap.put("applyCert", applyCert);
        return bizMap;
    }


    /**
     * 注册企业用户并申请证书
     *
     * @param account   企业注册账户
     * @param applyCert 是否申请证书 1 是 0 否
     * @param company   企业信息
     * @return 业务报文
     */
    public static Map<String, Object> packageCompanyApplyCertReq(String account, String applyCert, CompanyCertApplyVo company) {
        //1.业务报文
        Map<String, Object> bizMap = Maps.newHashMap();
        bizMap.put("account", account);
        bizMap.put("name", company.getName());
        bizMap.put("userType", String.valueOf(ContractUserTypeEnum.COMPANY.getType()));
        bizMap.put("mail", company.getMail());
        bizMap.put("mobile", company.getMobile());
        //2.企业证件信息对象
        JSONObject credential = new JSONObject();
        credential.put("regCode", company.getRegCode());
        credential.put("orgCode", company.getOrgCode());
        credential.put("taxCode", company.getTaxCode());
        credential.put("legalPerson", company.getLegalPerson());
        credential.put("legalPersonIdentity", company.getLegalPersonIdentity());
        credential.put("legalPersonIdentityType", company.getLegalPersonIdentityType().getType());
        credential.put("legalPersonMobile", company.getLegalPersonMobile());
        credential.put("contactMobile", company.getContactMobile());
        credential.put("contactMail", company.getContactMail());
        credential.put("province", company.getProvince());
        credential.put("city", company.getCity());
        credential.put("address", company.getAddress());
        bizMap.put("credential", credential);
        bizMap.put("applyCert", applyCert);
        return bizMap;
    }

    /**
     * 申请结果打包
     *
     * @param data 业务数据集
     * @return 结果对象
     */
    public static ApplyCertificateResVo packageApplyCertificateRes(String data) {
        ApplyCertificateResVo resVo = new ApplyCertificateResVo();
        HashMap dataMap = JSON.parseObject(data, HashMap.class);
        String taskId = String.valueOf(dataMap.get("taskId"));
        resVo.setTaskId(taskId);
        return resVo;
    }

    /**
     * 查询申请状态
     *
     * @param account 账户
     * @param taskId  任务Id
     * @return 结果
     */
    public static Map<String, Object> packageQueryApplyCertStatus(String account, String taskId) {
        //1.业务报文
        Map<String, Object> bizMap = Maps.newHashMap();
        bizMap.put("account", account);
        bizMap.put("taskId", taskId);
        return bizMap;
    }

    /**
     * 申请状态结果打包
     *
     * @param data 业务数据集
     * @return 结果对象
     */
    public static ApplyCertificateStatusResVo packageApplyCertificateStatusRes(String data) {
        ApplyCertificateStatusResVo resVo = new ApplyCertificateStatusResVo();
        HashMap dataMap = JSON.parseObject(data, HashMap.class);
        String message = String.valueOf(dataMap.get("message"));
        resVo.setMessage(message);
        String status = String.valueOf(dataMap.get("status"));
        resVo.setStatus(status);
        return resVo;
    }


    /**
     * 查询证书编号
     *
     * @param account 账户
     * @return 结果
     */
    public static Map<String, Object> packageQueryApplyCertId(String account) {
        //1.业务报文
        Map<String, Object> bizMap = Maps.newHashMap();
        bizMap.put("account", account);
        return bizMap;
    }

    /**
     * 查询证书编号结果
     *
     * @param data 业务数据集
     * @return 结果对象
     */
    public static String packageApplyCertificateNoRes(String data) {
        HashMap dataMap = JSON.parseObject(data, HashMap.class);
        String certId = String.valueOf(dataMap.get("certId"));
        return certId;
    }

}
